package com.rc.saas.mini.common.base;

import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * Created by sven on 2018-02-17 22:03
 */
public interface BaseService<K, E extends BaseModel, X, M extends BaseMapper<K, E, X>> {
    M getMapper();

    default Long countByExample(X example) {
        return getMapper().countByExample(example);
    }

    default int deleteByExample(X example) {
        return getMapper().deleteByExample(example);
    }

    default int deleteByPrimaryKey(K id) {
        return getMapper().deleteByPrimaryKey(id);
    }

    default int insert(E record) {
        return getMapper().insert(record);
    }

    default int insertSelective(E record) {
        return getMapper().insertSelective(record);
    }

    default List<E> selectByExample(X example) {
        return getMapper().selectByExample(example);
    }

    default E selectByPrimaryKey(K id) {
        return getMapper().selectByPrimaryKey(id);
    }

    default int updateByExampleSelective(@Param("record") E record, @Param("example") X example) {
        return getMapper().updateByExampleSelective(record, example);
    }

    default int updateByExample(@Param("record") E record, @Param("example") X example) {
        return getMapper().updateByExample(record, example);
    }

    default int updateByPrimaryKeySelective(E record) {
        return getMapper().updateByPrimaryKeySelective(record);
    }

    default int updateByPrimaryKey(E record) {
        return getMapper().updateByPrimaryKey(record);
    }
}
